package com.bj.dz.service.impl;

import com.bj.dz.entity.WaterPoolData;
import com.bj.dz.mapper.WaterPoolDataMapper;
import com.bj.dz.service.WaterPoolDataService;
import com.bj.dz.util.Constants;
import com.bj.dz.util.EmptyUtils;
import com.bj.dz.util.Page;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Slf4j
@Service
public class WaterPoolDataServiceImpl implements WaterPoolDataService {

    @Resource
    private WaterPoolDataMapper waterPoolDataMapper;

    public WaterPoolData getWaterPoolDataById(Integer id){
        return waterPoolDataMapper.getWaterPoolDataById(id);
    }

    public List<WaterPoolData>	getWaterPoolDataListByMap(Map<String,Object> param){
        return waterPoolDataMapper.getWaterPoolDataListByMap(param);
    }

    public Integer getWaterPoolDataCountByMap(Map<String,Object> param){
        return waterPoolDataMapper.getWaterPoolDataCountByMap(param);
    }

    @Transactional
    public boolean addWaterPoolData(WaterPoolData waterPoolData){
            return waterPoolDataMapper.insertWaterPoolData(waterPoolData)>0?true:false;
    }

    @Transactional
    public boolean modifyWaterPoolData(WaterPoolData waterPoolData){
        return waterPoolDataMapper.updateWaterPoolData(waterPoolData)>0?true:false;
    }

    @Transactional
    public boolean deleteWaterPoolDataById(Integer id){
        return waterPoolDataMapper.deleteWaterPoolDataById(id)>0?true:false;
    }

    public Page<WaterPoolData> queryWaterPoolDataPageByMap(Map<String,Object> param, Integer pageNo, Integer pageSize){
        Integer total = waterPoolDataMapper.getWaterPoolDataCountByMap(param);
        pageNo = EmptyUtils.isEmpty(pageNo) ? Constants.DEFAULT_PAGE_NO : pageNo;
        pageSize = EmptyUtils.isEmpty(pageSize) ? Constants.DEFAULT_PAGE_SIZE : pageSize;
        Page page = new Page(pageNo, pageSize, total);
        param.put("beginPos", page.getBeginPos());
        param.put("pageSize", page.getPageSize());
        List<WaterPoolData> waterPoolDataList = waterPoolDataMapper.getWaterPoolDataListByMap(param);
        page.setRows(waterPoolDataList);
        return page;
    }

}
